<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/1/24
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>文件导入</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css">

    <script src="../../js/jquery.min.3.1.0.js"></script>
</head>
<body>
<div class="layui-fluid" style="margin-top: 100px">
    <form id="myform" name="myform" class="layui-form" method="post" action="/ImportServlet"/>">
    <div class="layui-inline">
        <input type="file" id="file" name="file" style="align-items: center">
    </div>
    <div class="layui-inline">
        <button type="submit" class="layui-btn" style="align-items: center" lay-submit="" lay-filter="demo1">立即提交</button>
    </div>
    </form>
</div>

<script src="../../layuiadmin/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //创建一个编辑器
        layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function(data){
            $.ajax({
                url:"/ImportServlet",    //请求的url地址
                dataType:"json",   //返回格式为json
                contentType:"application/json",
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                data:{file: document.getElementById('file').files.item(0).name},  //参数值
                type:"GET",   //请求方式
                success:function(data){
                    //请求成功时处理
                    layer.alert(data.msg, function(index) {
                        //关闭窗口
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    })
                }
            });
            return false;
        });
    });
</script>

</body>

</html>


